package top.ezzz.db;

import cn.hutool.core.util.StrUtil;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import top.ezzz.config.DbConfig;

import java.io.Serializable;

/**
 * (ProcessInfo)实体类
 *
 * @author makejava
 * @since 2025-09-19 15:54:21
 */
@Slf4j
@Data
public class DbProcessInfo implements Serializable {
    private static final long serialVersionUID = -31731545704021687L;

    private Integer id;
    private String detail;

    private String pid;
    private String name;
    private String commandLine;
    private String user;
    private String cpuUsage;
    private String memoryUsage;
    private String startTime;
    private String upTime;

    public Object sink() {
        int insert = 0;
        try {
            Db db = DbConfig.getDb();
            String simpleName = this.getClass().getSimpleName();
            Entity entity = new Entity()
                    .setTableName(StrUtil.toUnderlineCase(simpleName))
                    .parseBean(this);
            insert = db.insert(entity);
            log.info("插入数据：{}", insert);
            return insert;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return insert;
    }

}

